<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>主页</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../css/iconfont.css" />

		<style>
			html,
			body {
				background-color: #efeff4;
			}
			
			h1 {
				color: #00ff00;
			}
			/*未点击色：#666666
			 * 点击色：#25CDDA */
			
			.mui-bar-tab .mui-tab-item.mui-active {
				color: #25CDDA;
			}
		</style>
	</head>

	<body>
		<header id="header" class="mui-bar mui-bar-nav" style="background: #27CDDB;">
			<h1 id="title" class="mui-title" style="color:#FFFFFF">首页</h1>
		</header>
		<nav class="mui-bar mui-bar-tab" id="bottomx">
			<a id="defaultTab" class="mui-tab-item mui-active" href="home.html">
				<span class="mui-icon iconfont icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a id="kuangjiTab" class="mui-tab-item" href="tabkuangji.html">
				<span class="mui-icon iconfont icon-shujuku"></span>
				<span class="mui-tab-label">矿机</span>
			</a>
			<a class="mui-tab-item" href="tabjiaoyi.html">
				<span class="mui-icon iconfont icon-jiaoyi"></span>
				<span class="mui-tab-label">C2C</span>
			</a>
			<a class="mui-tab-item" href="tabmy.html">
				<span class="mui-icon iconfont icon-wo"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" charset="utf-8">
			//mui初始化
			mui.init();
			var subpages = ['home.html', 'tabkuangji.html', 'tabjiaoyi.html', 'tabmy.html'];
			var subpage_style = {
				top: '45px',
				bottom: '51px'
			};

			var subpage_style2 = {
				top: '0px',
				bottom: '51px'
			};

			var aniShow = {};

			//创建子页面，首个选项卡页面显示，其它均隐藏；
			mui.plusReady(function() {
				//				设置bottom绝对位置,解决底部导航影响输入法的问题
				//document.getElementById('bottomx').style.top = (plus.display.resolutionHeight - 50) + "px";

				var self = plus.webview.currentWebview();
				for(var i = 0; i < 4; i++) {
					var temp = {};
					if(i == 3 || i == 0) {
						var sub = plus.webview.create(subpages[i], subpages[i], subpage_style2);
					} else {
						var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
					}
					if(i > 0) {
						sub.hide();
					} else {
						temp[subpages[i]] = "true";
						mui.extend(aniShow, temp);
					}
					self.append(sub);
				}
			});
			//当前激活选项
			var activeTab = subpages[0];
			var title = document.getElementById("title");
			var header = document.getElementById("header");

			//选项卡点击事件
			mui('.mui-bar-tab').on('tap', 'a', function(e) {
				var targetTab = this.getAttribute('href');
				if(targetTab == activeTab) {
					return;
				}

				var href = this.getAttribute('href');
				if(href == "tabmy.html" || href == "home.html") {
					header.style.display = "none";
				} else {
					header.style.display = "block";
				}
				//更换标题
				title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;

				//显示目标选项卡
				//若为iOS平台或非首次显示，则直接显示
				if(mui.os.ios || aniShow[targetTab]) {
					plus.webview.show(targetTab);
				} else {
					//否则，使用fade-in动画，且保存变量
					var temp = {};
					temp[targetTab] = "true";
					mui.extend(aniShow, temp);
					plus.webview.show(targetTab, "fade-in", 300);
				}
				//隐藏当前;
				plus.webview.hide(activeTab);
				//更改当前活跃的选项卡
				activeTab = targetTab;
			});

			var _toast = false;
			mui.back = function() {
				if(!_toast || !_toast.isVisible()) {
					_toast = mui.toast('', {
						duration: 'short',
						type: 'div'
					});
					plus.nativeUI.toast('再按一次返回键退出');
				} else {
					plus.runtime.quit();
				}
			}
		</script>
	</body>

</html>